name: Cache service CI/CD
on:
  push:
    branches:
      - master
jobs:
  build:
    name: Build and push Docker image
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source code
        uses: actions/checkout@v3
      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          java-version: '17'
          distribution: 'temurin'
          cache: 'gradle'
      - name: Grant execute for gradle
        run: chmod +x gradlew
      - name: Get application version
        run: echo "::set-output name=APP_VERSION::$(./gradlew -q printVersionName)"
        id: app_version
      - name: Build
        run: ./gradlew build -x test --no-daemon
      - name: Install docker
        uses: papodaca/install-docker-action@main
      - name: Log into registry
        uses: docker/login-action@v1
        with:
          registry: docker-registry.cr.cloud.ru
          username: ${{ secrets.CLOUD_ID }}
          password: ${{ secrets.CLOUD_SECRET }}
      - name: Build and Push container image to cloud evolution registry
        uses: docker/build-push-action@v4
        with:
          push: true
          tags: docker-registry.cr.cloud.ru/cache-service:${{ steps.app_version.outputs.APP_VERSION }}
          file: ./Dockerfile
          context: ./